package com.dykj.fireFighting.server.base.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.system.dto.DirectoryTypeDto;
import com.dykj.fireFighting.api.base.system.entity.SysDirectoryType;
import com.dykj.fireFighting.api.base.system.service.ISysDirectoryTypeService;
import com.dykj.fireFighting.api.base.system.vo.SysDirectoryTypeVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.system.mapper.SysDirectoryTypeMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据字典类型
 *
 * @Author hxb
 * @Date 2021-06-19 15:12:14
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class SysDirectoryTypeServiceImpl extends BaseServiceImpl<SysDirectoryTypeMapper, SysDirectoryType> implements ISysDirectoryTypeService {

    @Autowired
    private SysDirectoryTypeMapper sysDirectoryTypeMapper;

    @Override
    public PageVo<SysDirectoryTypeVo> queryDirectoryTypeList(DirectoryTypeDto directoryTypeDto) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(directoryTypeDto.getName())) {
            params.put("name", "%" + directoryTypeDto.getName() + "%");
        }
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(directoryTypeDto.getPage());
        // 设置页大小
        page.setSize(directoryTypeDto.getLimit());
        return new PageVo<SysDirectoryTypeVo>(sysDirectoryTypeMapper.queryDirectoryTypeList(page, params));
    }

    @Override
    public List<SysDirectoryType> queryDirectoryTypeAllList() {
        QueryWrapper<SysDirectoryType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_del", 0)
                .orderByAsc("sort");
        return sysDirectoryTypeMapper.selectList(queryWrapper);
    }
}
